package br.com.spam.pipeline.instruction.j;

import java.util.Map;

import br.com.spam.pipeline.core.ControlSignal;
import br.com.spam.pipeline.core.Processor;
import br.com.spam.pipeline.core.RegisterDataSource;
import br.com.spam.pipeline.instruction.JTypeInstruction;

public class JMP extends JTypeInstruction
{
	public static final int ID = 10;

	public JMP(String instruction, Processor processor)
	{
		super(instruction, processor);
	}

	@Override
	public String getInstructionAsString()
	{
		return String.format("I%d: %s %d", this.index(), this.name(), this.immediate());
	}

	@Override
	public boolean instructionFetch()
	{
		this.processor.getPC().lock();
		return true;
	}

	@Override
	public boolean instructionDecode()
	{
		this.processor.getPC().write(this.immediate(), RegisterDataSource.JustResolvedJump);
		return true;
	}

	@Override
	public final void generateControlSignals(Map<ControlSignal, Object> controlSignals)
	{
		controlSignals.put(ControlSignal.RegWrite, 0);
		controlSignals.put(ControlSignal.MemWrite, 0);
		controlSignals.put(ControlSignal.Branch, 0);
		controlSignals.put(ControlSignal.Jump, 1);
	}
}
